package crl.menu.view
{
	import caurina.transitions.Tweener;
	
	import crl.menu.data.Item;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class ItemRender extends Sprite
	{
		private var w:int;
		
		private var tf:TextField;
		private var bg:Sprite;
		private var _data:Item;
		public function ItemRender()
		{
			var item:ItemSkin=new ItemSkin();
			this.addChild(item);
			tf=item.tf;
			
			bg=item.bg;
			
			
			this.mouseChildren=false;
			this.buttonMode=true;
			
			
			addEventListener(MouseEvent.ROLL_OVER,mouseHandler);
			addEventListener(MouseEvent.ROLL_OUT,mouseHandler);
		}
		
		private function mouseHandler(event:MouseEvent):void{
			
			if(event.type==MouseEvent.ROLL_OVER){
				
				Tweener.addTween(bg, {alpha:1, time:1});
			}else{
				Tweener.addTween(bg, {alpha:0, time:1});
			}
		}
		
		public function set templete(value:DisplayObject):void{
			w=value.width;
			bg.alpha=0;
		}
		
		
		public function set data(value:Item):void{
			_data=value;
			
			tf.htmlText=_data.label;
			
			var tfw:int=tf.textWidth;
			
			tf.x=(w-tfw)>>1;
			
			bg.x=tf.x-5;
			bg.width=tfw+15;
			bg.height=tf.textHeight+2;
		}
		
		public function get data():Item{
			return _data;
		}
	}
}